package com.it.park.rms.job;

import java.util.List;

import javax.annotation.Resource;

import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.dataflow.DataflowJob;
import com.it.park.rms.client.model.User;
import com.it.park.rms.client.service.UserService;
import com.it.park.rms.common.util.empty.EmptyUtil;

public class UpdateUserIntegralJob implements DataflowJob<User>{

	@Resource
	private UserService userService;
	
	@Override
	public List<User> fetchData(ShardingContext arg0) {
		System.out.println("参数值："+arg0.getShardingParameter());
		System.out.println(arg0.getShardingItem());
		User user = new User();
		user.setShardingParameter(Integer.parseInt(arg0.getShardingParameter()));
		return userService.selectByModel(user);
	}

	@Override
	public void processData(ShardingContext arg0, List<User> list) {
		if(EmptyUtil.isEmpty(list)){
			return;
		}
		User user = null;
		for (int i = 0; i < list.size(); i++) {
			user = list.get(i);
			user.setIntegral(user.getIntegral()+30);
			userService.updateUserIntegral(user);
		}
		
	}

}
